//
//  PopView.m
//  Created by 杨政涛 on 16/7/14.
//  Copyright © 2016年 51ledian.com. All rights reserved.
//

#import "PopView.h"
#import "AppDelegate.h"

@implementation PopView

- (instancetype)initWithCreatPopViewframe:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.windowShadowView = [[UIView alloc] init];
        self.windowShadowView.userInteractionEnabled = YES;
        self.windowShadowView.hidden = YES;
        self.windowShadowView.frame = frame;
        self.windowShadowView.backgroundColor = [UIColor colorWithWhite:0.000 alpha:0.3500];
        AppDelegate *app=(AppDelegate *)[UIApplication sharedApplication].delegate;
        [app.window.rootViewController.view addSubview:self.windowShadowView];
        
        //bgView
        UIView *backgroundView = [[UIView alloc]init];
        backgroundView.backgroundColor = [UIColor whiteColor];
        backgroundView.userInteractionEnabled = YES;
        backgroundView.layer.masksToBounds = YES;
        backgroundView.layer.cornerRadius = 5;
        [self.windowShadowView addSubview:backgroundView];
        [backgroundView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.windowShadowView).offset(30);
            make.right.equalTo(self.windowShadowView).offset(-30);
            make.height.equalTo(@(SCREEN_HEIGHT/2));
            make.centerY.equalTo(self.windowShadowView);
        }];
        
        
        UIImageView *cancleButtonImageView = [[UIImageView alloc]init];
        cancleButtonImageView.image = [UIImage imageNamed:@"lALOW3IKWi8v_47_47"];
        [self.windowShadowView addSubview:cancleButtonImageView];
        [cancleButtonImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.equalTo(@(20));
            make.height.equalTo(@(20));
            make.centerX.equalTo(backgroundView.mas_right).offset(-25);
            make.centerY.equalTo(backgroundView.mas_top).offset(25);
        }];
        
        UIButton *cancleButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [cancleButton addTarget:self action:@selector(cancleAction) forControlEvents:UIControlEventTouchUpInside];
        [self.windowShadowView addSubview:cancleButton];
        [cancleButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.equalTo(@(50));
            make.height.equalTo(@(50));
            make.top.equalTo(backgroundView.mas_top);
            make.right.equalTo(backgroundView.mas_right);
          
        }];
        self.iconView = [[UIImageView alloc]init];
        self.iconView.userInteractionEnabled = YES;
        [backgroundView addSubview:self.iconView];
        [self.iconView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(70, 70));
            make.top.equalTo(backgroundView).offset(50);
            make.centerX.equalTo(backgroundView);
            
        }];
        self.iconView.layer.cornerRadius = 35;
        self.iconView.layer.masksToBounds = YES;
        self.iconView.image = [UIImage imageNamed:@"b1"];
        
        self.BossName = [[UILabel alloc]init];
        self.BossName.textColor = COLOR_FONT_BLACK;
        self.BossName.font = [UIFont systemFontOfSize:15];
        self.BossName.textAlignment = 1;
        [backgroundView addSubview:self.BossName];
        [self.BossName mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.iconView.mas_bottom).offset(10);
            make.left.equalTo(@(0));
            make.right.equalTo(backgroundView);
            make.height.equalTo(@(30));
        }];
        
        self.BossJob = [[UILabel alloc]init];
        self.BossJob.textColor = COLOR_FONT_BLACK;
        self.BossJob.font = [UIFont systemFontOfSize:15];
        self.BossJob.textAlignment = 1;
        [backgroundView addSubview:self.BossJob];
        [self.BossJob mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.BossName.mas_bottom);
            make.left.equalTo(@(0));
            make.right.equalTo(backgroundView);
            make.height.equalTo(@(30));
        }];

        self.BossIntroduce = [[UILabel alloc]init];
        self.BossIntroduce.textColor = COLOR_FONT_BLACK;
        self.BossIntroduce.font = [UIFont systemFontOfSize:15];
        self.BossIntroduce.numberOfLines = 0;
        [backgroundView addSubview:self.BossIntroduce];
        [self.BossIntroduce mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.BossJob.mas_bottom).offset(10);
            make.left.equalTo(@(30));
            make.right.equalTo(backgroundView).offset(-30);
            make.bottom.equalTo(backgroundView).offset(-10);
        }];
    }
    return self;
}

- (void)setCompanyInfo:(DDCompanyInfo *)companyInfo
{
    _companyInfo = companyInfo;
    
    NSString *url = [DDAPIGenerate imageURLWithPath:companyInfo.ceo_logo];
    [self.iconView  sd_setImageWithURL:[NSURL URLWithString:url] placeholderImage:[UIImage imageNamed:@"default_header"]];
    self.BossName.text = companyInfo.ceo_name;
    self.BossJob.text = companyInfo.ceo_position_customized ? companyInfo.ceo_position_customized : companyInfo.ceo_position_name;
    self.BossIntroduce.text = companyInfo.ceo_intro;
}

- (void)cancleAction
{
    self.windowShadowView.hidden = YES;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
